package com.servlet.yanglaoyuan.mapper;

import com.servlet.yanglaoyuan.pojo.Medication_Record;
import com.servlet.yanglaoyuan.pojo.dataFilter;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface Medication_RecordMapper {

    @Results({
            @Result(property = "date", column = "date", javaType = LocalDateTime.class)
    })
    /**
     * 添加一条用药记录
     */
    @Insert("insert into medication_record(elderly_id,medication_name,dosage,frequency,date,duration,doctor,status,notes) " +
            "values(#{elderlyId},#{medicationName},#{dosage},#{frequency},#{date},#{duration},#{doctor},#{status},#{notes})")
    public void add(Medication_Record medication_record);
    /**
     * 修改一条用药记录
     */
    public void updateRecord(Medication_Record medication_record);
    /**
     * 筛选出用药记录
     */
    public List<Medication_Record> getRecord(dataFilter record);
    /**
     * 根据药物名称查询一条用药记录
     */
    @Select("select * from medication_record where medication_name=#{medicationName}")
    public List<Medication_Record> getByName(String medicationName);
    /**
     * 根据用药状态查询一条用药记录
     */
    @Select("select * from medication_record where status= #{status}")
    public List<Medication_Record> getByStatus(String status);
    /**
     * 根据用药日期查询一条用药记录,日期在两个时间段之间
     */
    @Select("select * from medication_record where date between #{startDate} and #{endDate}")
    public List<Medication_Record> getByDate(LocalDateTime startDate, LocalDateTime endDate);
    /**
     * 删除一条用药记录
     */
    @Insert("delete from medication_record where id= #{id}")
    public void deleteRecord(Integer id);
    /**
     * 查询全部用药记录
     */
    @Select("select * from medication_record")
    public List<Medication_Record> getAll();

    /**
     * 根据老人id查询该老人用药记录
     */
    @Select("select * from medication_record where elderly_id= #{elderlyId}")
    public List<Medication_Record> getByElderlyId(Integer elderlyId);

}
